package com.zzh.phone.hviews;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.ListView;

import com.zzh.lib.views.adapter.HBaseAdapter;
import com.zzh.lib.views.adapter.holder.HSuperViewHolder;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class ListActivity extends AppCompatActivity {

    public Handler mHandler;
    HBaseAdapter<String> adapter;
    ListView lv;
    int page = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        lv = findViewById(R.id.lv_list);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add("测试 " + i);
        }
        adapter = new HBaseAdapter<>() {
            int pageSize;

            @Override
            protected int getLayoutRes() {
                return R.layout.item_lv;
            }

            @Override
            public String getItem(int position) {
                if (position >= pageSize) {
                    int p = position % pageSize;
                    return mData.get(p);
                }
                return mData.get(position);
            }

            @Override
            public int getCount() {
                pageSize = mData.size();
                return Integer.MAX_VALUE;
            }

            @Override
            protected void onBindViewData(HSuperViewHolder holder, String item, int position) {
                holder.setText(R.id.text, item);
            }
        };
        adapter.addAll(list);
        lv.setAdapter(adapter);
        mHandler = new Handler(Looper.myLooper()) {

            @Override
            public void handleMessage(@NonNull Message msg) {
                switch (msg.what) {
                    case 0:
                        break;

                }
            }
        };
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                mHandler.sendEmptyMessage(0);
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 3000, 2000);

    }
}